﻿// 2023/3/8: 首个版本

using System;
using System.IO;
using Eto.Forms;
using Eto.Drawing;
using ASEva;
using ASEva.Samples;
using ASEva.UIEto;

namespace CommonSource
{
    class OfflineMapPathDialog : DialogPanel
    {
        public OfflineMapPathDialog(String path, CommonImage icon = null)
        {
            MapPath = path;

            if (icon != null) Icon = new Icon(1, icon.ToEtoBitmap());
            Title = chinese ? "离线地图" : "Offline map";
            SetFixMode(310, 45, true);

            var mainLayout = this.SetContentAsRowLayout();
            mainLayout.AddLabel(chinese ? "路径:" : "Path:");
            var linkPath = mainLayout.AddLinkButton(chinese ? "(未配置)" : "(Not configured)", true);
            var buttonRemove = mainLayout.AddButton(chinese ? "移除" : "Remove", false, 80);

            if (path != null)
            {
                linkPath.Text = Path.GetFileName(MapPath);
            }

            linkPath.Click += delegate
            {
                var dialog = new OpenFileDialog();
                dialog.Title = chinese ? "请选择一个gmdb文件" : "Please select a gmdb file";
                dialog.Filters.Add(new FileFilter(chinese ? "离线地图文件 (*.gmdb)" : "Offline Map File (*.gmdb)", ".gmdb"));
                if (MapPath != null) dialog.Directory = new Uri(Path.GetDirectoryName(MapPath));
                if (dialog.ShowDialog(null) == DialogResult.Ok)
                {
                    MapPath = dialog.FileName;
                    linkPath.Text = Path.GetFileName(MapPath);
                }
            };

            buttonRemove.Click += delegate
            {
                MapPath = null;
                linkPath.Text = chinese ? "(未配置)" : "(Not configured)";
            };
        }

        public String MapPath { get; set; }

        private bool chinese = Agency.GetAppLanguage() == "ch";
    }
}